<script setup lang="ts">
import { ref } from 'vue'
import { $Login, $Register } from '@/api/user';
import { $AbminLogin } from '@/api/admin';

// 登录与注册切换
var showRegister = ref(false)

// 登录
var id = ref(null)
var name = ref('')
const login = () => {
    if (id.value < 30000000) {
        $Login({
            id: id.value,
            userpassword: userpassword.value
        })
    } else {
        $AbminLogin({
            id: id.value,
            password: userpassword.value
        })
    }
}

// 注册
var userpassword = ref('')
var newpassword = ref('')
const register = () => {
    $Register({
        name: name.value,
        userpassword: newpassword.value
    })
}
</script>

<template>
    <div class="container">
        <div class="login-container" :style="{ justifyContent: showRegister ? 'flex-start' : 'flex-end' }">
            <transition name="fade-register">
                <div v-show="showRegister" class="register-form">
                    <div class="logo">
                        <img src="@/assets/zhihui-logo-o.png" alt="">
                        <span>智慧医疗</span>
                    </div>
                    <div class="title">
                        <h1>注册</h1>
                        <div>
                            <span>已有账号？</span>
                            <div class="span" @click="showRegister = false">登录</div>
                        </div>
                    </div>
                    <div class="form-bd">
                        <div class="row">
                            <input type="text" placeholder="用户名" class="form-inner" v-model="name">
                        </div>
                        <div class="row">
                            <input type="text" placeholder="输入密码" class="form-inner" v-model="newpassword">
                        </div>
                        <div class="row col" style="margin: 30px auto;">
                            <button @click="register">注册</button>
                        </div>
                    </div>
                </div>
            </transition>

            <transition name="fade-login">
                <div v-show="!showRegister" class="login-form">
                    <div class="logo">
                        <img src="@/assets/zhihui-logo-o.png" alt="">
                        <span>智慧医疗</span>
                    </div>
                    <div class="title">
                        <h1>登录</h1>
                        <div>
                            <span>还没有账号？</span>
                            <div class="span" @click="showRegister = true">免费注册</div>
                        </div>
                    </div>
                    <div class="form-bd">
                        <div class="row">
                            <input type="text" placeholder="账号" class="form-inner" v-model="id">
                        </div>
                        <div class="row">
                            <input type="text" placeholder="输入密码" class="form-inner" v-model="userpassword">
                        </div>
                        <div class="row col">
                            <span>找回密码</span>
                            <button @click="login">登录</button>
                        </div>
                        <div class="login-mode">
                            <div class="left"></div>
                            <div class="center">或者使用一键登录</div>
                            <div class="right"></div>
                        </div>
                        <div class="icon-box">
                            <div><img src="@/images/login/icon-wx.png" alt=""></div>
                            <div><img src="@/images/login/icon-qq.png" alt=""></div>
                        </div>
                    </div>
                </div>
            </transition>
        </div>
    </div>
</template>

<style scoped lang="scss">
.fade-login-enter-active,
.fade-login-leave-active,
.fade-register-enter-active,
.fade-register-leave-active {
    transition: opacity 0.5s, transform 0.5s;
}

.fade-register-leave-active,
.fade-login-enter-active {
    opacity: 0;
    transform: translateX(100%);
}

.fade-register-enter-active,
.fade-login-leave-active {
    opacity: 0;
    transform: translateX(-100%);
}

.container {
    display: flex;
    height: 100vh;
    background: url(@/images/login/bg.jpg) no-repeat;
    background-position: center center;
    background-size: cover;

    .login-container {
        display: flex;
        justify-content: end;
        margin: auto;
        width: 100%;
        height: 540px;
        max-height: 540px;
        max-width: 960px;
        background-color: hsla(0, 0%, 100%, .7);

        .login-form,
        .register-form {
            padding: 40px 50px;
            width: 50%;
            background-color: #fff;

            .logo {
                display: flex;
                align-items: center;
                height: 22px;
                margin-bottom: 20px;

                img {
                    height: 100%;
                    margin-right: 15px;
                }

                span {
                    font-size: 18px;
                    color: #333;
                }
            }

            .title {
                text-align: center;

                h1 {
                    margin: 10px 0;
                    font-weight: normal;
                }

                div {
                    span {
                        font-size: 16px;
                        color: #93969a;
                        font-weight: 300;
                    }

                    .span {
                        display: inline-block;
                        text-decoration: none;
                        color: #4b7fdb;
                        cursor: pointer;
                    }
                }
            }

            .form-bd {
                display: flex;
                flex-direction: column;

                .row {
                    margin: 20px 0;
                    padding: 5px 0;

                    .form-inner {
                        width: 100%;
                        height: 36px;
                        font-size: 16px;
                        line-height: 18px;
                        border: none;
                        border-bottom: 1px solid #d8d8d8;
                    }
                }

                .col {
                    display: flex;
                    flex-direction: row;
                    justify-content: space-between;
                    align-items: center;

                    span {
                        font-size: 16px;
                        color: #93969a;
                    }

                    button {
                        width: 100px;
                        height: 36px;
                        background-color: #000;
                        color: #fff;
                    }
                }

                .login-mode {
                    display: flex;
                    justify-content: space-between;
                    align-items: center;

                    .left {
                        flex: 1;
                        height: 1px;
                        background-color: #d8d8d8;
                    }

                    .center {
                        line-height: 16px;
                        color: #93969a;
                        font-style: 16px;
                        margin: 0 26px;
                        font-weight: 300;
                    }

                    .right {
                        flex: 1;
                        height: 1px;
                        background-color: #d8d8d8;
                    }
                }

                .icon-box {
                    display: flex;
                    justify-content: center;
                    margin: 25px 0;

                    div {
                        width: 36px;
                        height: 36px;
                        margin: 0 50px;
                        border-radius: 50%;

                        img {
                            width: 100%;
                        }
                    }
                }
            }
        }
    }
}
</style>